/**
 * @author 黄波
 * 创建日期：2011Oct 15, 2011
 * TODO// N/A
 */
package com.platform.res.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.platform.bean.PageBean;
import com.platform.os.util.Util;
import com.platform.pojo.ResInfo;
import com.platform.pojo.ResType;
import com.platform.pojo.TmpRes;
import com.platform.pojo.UserInfo;
import com.platform.res.bean.ResInfoBean;
import com.platform.res.bo.ResBo;
import com.platform.user.bo.UserBo;

/**
 * 加载临时资源（只有本人可见）
 */
public class LoadTmpResAction extends ResourceSupport {

	private PageBean pageBean;
	private List<TmpRes> items;
	private String nodeId;
	private String nodeText;
	
	@Override
	public String execute() throws Exception {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		HttpSession session = ServletActionContext.getRequest().getSession();
		UserInfo user = (UserInfo) session.getAttribute("user");
		if(user == null) {
			out.flush();
			out.write("<script>alert('请先登录！');history.back();</script>");
			out.close();
			return null;
		}
		ResBo bo = ResBo.getInstance();
		Object[] objs = bo.getTmpRes(pageBean, user.getId().toString());
		pageBean = (PageBean)objs[0];
		items = (List)objs[1];
		if(nodeText != null) {
			nodeText = new String(nodeText.getBytes("iso-8859-1"), "utf-8");
		}
		return SUCCESS;
	}
	/**
	 * @param typeId
	 * @return
	 */
	private ResType getTypeName(Integer typeId, List<ResType> types) {
		for(ResType item : types) {
			if(item.getId() == typeId) {
				return item;
			}
		}
		return null;
	}
	public PageBean getPageBean() {
		return pageBean;
	}
	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}
	public List<TmpRes> getItems() {
		return items;
	}
	public void setItems(List<TmpRes> items) {
		this.items = items;
	}
	public String getNodeId() {
		return nodeId;
	}
	public void setNodeId(String nodeId) {
		this.nodeId = nodeId;
	}
	public String getNodeText() {
		return nodeText;
	}
	public void setNodeText(String nodeText) {
		this.nodeText = nodeText;
	}
}
